package com.cloud.bssp.reference;

/**
 * @description： ThreadLocal与弱引用
 * @author：weirx
 * @date：2021/5/20 10:07
 * @version：3.0
 */
public class ThreadLocalAndWeakReference {

    static class Student {
        private String name;

        public Student(String name) {
            this.name = name;
        }
    }

    static ThreadLocal threadLocal = new ThreadLocal();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            threadLocal.set(new Student("zhangsan"));
        }).start();

        Thread.sleep(1000);
        new Thread(() -> {
            System.out.println(threadLocal.get());
        }).start();
    }
}
